package com.hugegis.usePublic;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.hugegis.SmarHMETER.CBApplication;

import android.app.Activity;

public class ConfigResolve extends DefaultHandler {
	private CBApplication app;

	public ConfigResolve(Activity activity) {
		app = (CBApplication) activity.getApplication();
	}

	@Override
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		if (localName.equals("mapUrl")) {
			for (int i = 0; i < attributes.getLength(); i++) {
				if (attributes.getLocalName(i).equals("mapURL"))
					app.setMapURL(attributes.getValue("mapURL"));

				if (attributes.getLocalName(i).equals("X1"))
					app.setX1(Double.valueOf(attributes.getValue("X1")));

				if (attributes.getLocalName(i).equals("Y1"))
					app.setY1(Double.valueOf(attributes.getValue("Y1")));

				if (attributes.getLocalName(i).equals("X2"))
					app.setX2(Double.valueOf(attributes.getValue("X2")));

				if (attributes.getLocalName(i).equals("Y2"))
					app.setY2(Double.valueOf(attributes.getValue("Y2")));
			}
		}
		if (localName.equals("httpServiceLAN")) {
			for (int i = 0; i < attributes.getLength(); i++) {
				if (attributes.getLocalName(i).equals("strUrl"))
					app.setHttpLanURL(attributes.getValue("strUrl"));
			}
		}
		if (localName.equals("httpServiceUrl")) {
			for (int i = 0; i < attributes.getLength(); i++) {
				if (attributes.getLocalName(i).equals("strUrl")) {
					String wlanURL=attributes.getValue("strUrl");
					app.setHttpWanURL(wlanURL);
					app.setHttpServicestrUrl(wlanURL);
				}
			}
		}
	}

	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		super.endElement(uri, localName, qName);
	}

}
